package com.logic.modular.act.cultivate;

import com.comment.util.JwtUtils;
import com.comment.util.message.ResponseResult;
import com.logic.modular.act.cultivate.vo.AchievementActionVo;
import com.logic.modular.game.achievement.AchievementServiceImpl;
import com.logic.modular.game.statistical.domain.PlayerStatisticalPool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 成就
 */
@Slf4j
@Api(tags = "成就")
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("/achievementAct")
public class AchievementAction {
    @Resource
    private AchievementServiceImpl achievementService;

    @ApiOperation(value = "获取列表")
    @PostMapping("/list")
    public ResponseResult<?> list() {
        return ResponseResult.success(achievementService.list());
    }

    @ApiOperation(value = "查看进度")
    @PostMapping("/viewProgress")
    public ResponseResult<PlayerStatisticalPool> viewProgress(@RequestHeader String token) {
        return ResponseResult.success(achievementService.viewProgress(JwtUtils.getPlayerId(token)));
    }

    @ApiOperation(value = "查看已领取成就等级奖励")
    @PostMapping("/grade/viewReceivedAchievementLevelRewards")
    public ResponseResult<?> viewReceivedAchievementLevelRewards(
            @RequestHeader String token
    ) {
        return ResponseResult.success(achievementService.viewReceivedAchievementLevelRewards(JwtUtils.getPlayerId(token)));
    }

    @ApiOperation(value = "领取成就等级奖励")
    @PostMapping("/grade/claimRewards")
    public ResponseResult<?> gradeClaimRewards(
            @RequestHeader String token,
            @RequestBody AchievementActionVo.gradeClaimRewards vo
    ) {
        return ResponseResult.success(achievementService.gradeClaimRewards(JwtUtils.getPlayerId(token), vo.getId()));
    }
}
